export const isEmpty = (val: any) => {
  if (val == null) return true
  if (typeof val === "number") return !val
  if (typeof val === "boolean") return false

  switch (Object.prototype.toString.call(val)) {
    case "[object Array]":
    case "[object String]": {
      return !val.length
    }
    case "[object Set]":
    case "[object Map]":
    case "[object File]": {
      return !val.size
    }
    case "[object Object]": {
      return !Object.keys(val).length
    }
  }
  return true
}

export const isNotEmpty = (val: any) => !isEmpty(val)

export const isWeixin = () => {
  return window.navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1;
};

export const isIOS = () => {
  return /(iPhone|iPad|iPod|iOS)/i.test(window.navigator.userAgent);
};

export const isAndroid = () => {
  return /Android/i.test(window.navigator.userAgent);
};

export const toString = (data:any) => {
  return Object.prototype.toString.call(data)
}

export const isObject = (data: any) => {
  return toString(data) === '[object Object]';
};

export const isArray = (data: any) => {
  return Object.prototype.toString.call(data) === "[object Array]"
}

/**
 * 传进来的数据只要有一个为空, 就返回true
 * 
 * @returns 
 */
export function isBlanks(...args: any[]) {
  for (let i = 0; i < args.length; i++) {
      if (isEmpty(args[i])) return true;
  }
  return false;
}